package com.crl.animation.resource
{
	import com.crl.animation.pak.FrameDef;
	import com.crl.animation.pak.PakDef;
	import com.crl.events.RemoteEvent;
	import com.crl.net.NetStatus;
	
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.geom.Matrix;
	import flash.utils.ByteArray;

	/**
	 * pak资源; 
	 * @author crl
	 * 
	 */	
	public class PakResource extends AbstractResource
	{
		protected var _data:PakDef;
		protected var _bmd:BitmapData;
		
		
		protected var _m:Matrix;
		public function PakResource()
		{
			_m=new Matrix();
		}
		
		
		override protected function successHandler(event:RemoteEvent):void{
			var data:ByteArray=event.data;
			
			//todo decode;
			
			//end decode;
			
			_status=NetStatus.READY;
		}
		
		public function get data():PakDef{
			return _data;
		}
		
		
		/**
		 * 
		 * @param g
		 * @param dirction
		 * @param action
		 * @param frame
		 * 
		 */		
		public function draw(g:Graphics,dirction:int,action:int,frame:int):void{
			
			
			var d:FrameDef=_data.getFrame(dirction,action,frame);
			
			_m.tx=d.ox;
			_m.ty=d.oy;
			
			g.beginBitmapFill(_bmd,_m);
			g.drawRect(d.ix,d.iy,d.w,d.h);
			
		}
	}
}